package com.hy.admin.service.impl;

import com.hy.admin.dao.FeedbackDao;
import com.hy.admin.entity.FeedbackEntity;
import com.hy.admin.service.FeedbackService;
import com.hy.core.response.ServicesResult;
import org.apache.commons.httpclient.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;

@Service
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackDao feedbackDao;

    @Override
    public ServicesResult<Boolean> add(FeedbackEntity feedbackEntity) {
        ServicesResult<Boolean> servicesResult = new ServicesResult<>();
        //校验请求参数
        if (feedbackEntity == null){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("请求报文有误");
            return servicesResult;
        }
        //校验必填参数
        if(feedbackEntity.getMobile() == null){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("手机号不能为空");
            return servicesResult;
        }
        if(feedbackEntity.getContent() == null || "".equals(feedbackEntity.getContent())){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("反馈内容不能为空");
            return servicesResult;
        }
        Calendar cal = Calendar.getInstance();
        feedbackEntity.setCreateTime(cal.getTime());
        feedbackEntity.setUpdateTime(cal.getTime());
        //插入数据
        int result = feedbackDao.insertSelective(feedbackEntity);
        servicesResult.setResult(result == 1 ? true : false);
        return servicesResult;
    }
}
